package com.bwie.service.impl;

import com.bwie.mapper.RegistrationMapper;
import com.bwie.mapper.VisitMapper;
import com.bwie.pojo.Result;
import com.bwie.pojo.dto.VisitDto;
import com.bwie.pojo.po.VisitPo;
import com.bwie.pojo.vo.RegistrationVo;
import com.bwie.pojo.vo.VisitVo;
import com.bwie.service.VisitService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @
 * @descriptions: VisitServiceImpl
 * @author: LiYang
 * @date: 2025/3/17 0:09
 * @version: 1.0
 */
@Service
public class VisitServiceImpl implements VisitService {
    @Autowired
    private VisitMapper visitMapper;
    @Autowired
    private RegistrationMapper registrationMapper;
    @Override
    @Transactional
    public Result updAdd(RegistrationVo registrationVo) {
       registrationMapper.updStatus(registrationVo.getRegistrationId());
        VisitPo visitPo = new VisitPo();
        visitPo.setAge(registrationVo.getAge());
        visitPo.setVisitType(registrationVo.getRegistrationType());
        visitPo.setBirthDate(registrationVo.getBirthDate());
        visitPo.setSex(registrationVo.getSex());
        visitPo.setDepartmentId(registrationVo.getDepartmentId());
        visitPo.setDoctorId(registrationVo.getUid());
        visitPo.setIdCard(registrationVo.getIdCard());
        visitPo.setPatientName(registrationVo.getPatientName());
        visitPo.setPhoneNumber(registrationVo.getPhoneNumber());
        visitPo.setRegistrationId(registrationVo.getRegistrationId());
        visitPo.setCreatTime(new Date());
        visitMapper.add(visitPo);
        return Result.success("就诊成功");
    }

    @Override
    public Result getList(VisitDto visitDto) {
        PageHelper.startPage(visitDto.getPageNum(),visitDto.getPageSize());
        List<VisitVo> list=visitMapper.getList(visitDto);
        PageInfo<VisitVo> visitVoPageInfo = new PageInfo<>(list);
        return Result.success("查询成功",visitVoPageInfo);
    }

    @Override
    public VisitVo selectId(Integer visitId) {
        return visitMapper.select(visitId);
    }
}
